#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

#define N 100001
int dp[N][6];
int n;
pair<int, int> now; //L长度, K“等级”;
pair<int, int> ans;

int main(){
    cin >> n;
    int x, y;
    for(int i = 1; i <= n; i++){
        scanf("%d %d", &x, &y);
        dp[i][x] = dp[i - 1][x] + 1;
        dp[i][y] = dp[i - 1][y] + 1;
        if(dp[i][x] > dp[i][y]){
            now.first = dp[i][x];
            now.second = x;
        }else if(dp[i][x] < dp[i][y]){
            now.first = dp[i][y];
            now.second = y;
        }else{
            now.first = dp[i][x];
            now.second = min(x, y);
        }
        if(now.first > ans.first){
            ans.first = now.first;
            ans.second = now.second;
            continue;
        }
        if(now.first > ans.first){
            ans.second = min(ans.second, now.second);
            continue;
        }
    }
    printf("%d %d", ans.first, ans.second);
    return 0;
}